﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;


public partial class SpecialPlan_SpecialPlanResolveAdd : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (dllAuthentication.IsManager(objUserInfo.UserName) > 0)
        {
            this.btnAdd.Enabled = true;
            this.btnModify.Enabled = true;
            this.btnOk.Enabled = true;
        }
        else
        {
            this.btnAdd.Enabled = false;
            this.btnModify.Enabled = false;
            this.btnOk.Enabled = false;
        }
        if (!IsPostBack)
        {
            object[] _valueSpecial = new object[1];
            _valueSpecial[0] = Utility.HttpHelp.getParamsInt("SpecialPlanId");
            DataTable _SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(_valueSpecial);
            if (_SpecialPlan.Rows.Count > 0)
            {
                this.txtMasterDepartment.Text = _SpecialPlan.Rows[0]["MasterDepartment"].ToString();
                this.txtMasterPeople.Value = _SpecialPlan.Rows[0]["MasterPeople"].ToString();
                this.txtEvaluatePeople.Value = _SpecialPlan.Rows[0]["EvaluatePeople"].ToString();
            }
            bindSpecialPlan();

        }
    }


    /// <summary>
    /// 绑定空记录表头GridView
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-16</date>
    void bindSpecialPlan()
    {
        object[] _value = new object[1];
        _value[0] = Utility.HttpHelp.getParamsInt("SpecialPlanId");
        DataTable dt = new BLL.SpecialPlan().GetSpecialPlanDetailBySpecialId(_value);

        if (dt.Rows.Count > 0)
        {
            this.gdvSpecialPlanResolve.DataSource = dt;
            this.gdvSpecialPlanResolve.DataBind();
            for (int i = 0; i < this.gdvSpecialPlanResolve.Rows.Count; i++)
            {
                wrapByComma(this.gdvSpecialPlanResolve, i, 8);
                if (Convert.ToInt32(gdvSpecialPlanResolve.DataKeys[i]["State"].ToString()) == 1
                    || Convert.ToInt32(gdvSpecialPlanResolve.DataKeys[i]["State"].ToString()) == 2
                    || Convert.ToInt32(gdvSpecialPlanResolve.DataKeys[i]["State"].ToString()) == 9)
                {
                    gdvSpecialPlanResolve.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
            }
            this.txtSpecialPlanDetailSortId.Value = "专" + Utility.HttpHelp.getParamsString("SpecialPlanSortId") + "." + (this.gdvSpecialPlanResolve.Rows.Count + 1).ToString();
        }
        else
        {

            DataTable SpecialPlan = createDataTable();
            DataRow dr = SpecialPlan.NewRow();
            SpecialPlan.Rows.Add(dr);
            this.gdvSpecialPlanResolve.DataSource = SpecialPlan;
            this.gdvSpecialPlanResolve.DataBind();
            //隐藏首行，只保留表头
            this.gdvSpecialPlanResolve.Rows[0].Visible = false;
            this.txtSpecialPlanDetailSortId.Value = "专" + "1." + this.gdvSpecialPlanResolve.Rows.Count.ToString();
        }
    }


    /// <summary>
    /// 判断控件值是否为空
    /// </summary>
    /// <returns>空返回0，有值返回1</returns>
    /// <author>grokyao</author>
    /// <date>2009-2-17</date>
    int isNull()
    {
        #region 验证是否为空
        if (this.txtCompleteTime.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtMasterPeople.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtWorkItem.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtSlaveDepartment.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtStartTime.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtEvaluatePeople.Value.Length == 0)
        {
            return 0;
        }
        return 1;
        #endregion
    }
    /// <summary>
    /// 时间验证
    /// </summary>
    bool verifyDate()
    {
        #region 必要验证判断
        //判断完成时间是否大于起始时间

        DateTime _startTime = Convert.ToDateTime(this.txtStartTime.Text.Trim());
        DateTime _endTime = Convert.ToDateTime(this.txtCompleteTime.Text.Trim());
        if (_startTime > _endTime)
        {
            Utility.HttpHelp.alert("完成时间需要大于起始时间", Page);
            return false;
        }


        return true;
        #endregion
    }

    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");
    }

    /// <summary>
    /// 返回事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-17</date>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        Utility.HttpHelp.closeWindowNoFresh("AddSpecialPlan.aspx", Page);
    }


    /// <summary>
    /// 全选事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ckbAllSelect_CheckedChanged(object sender, EventArgs e)
    {
        if (this.ckbAllSelect.Checked == true)
        {
            for (int i = 0; i < this.gdvSpecialPlanResolve.Rows.Count; i++)
            {
                CheckBox _chk = ((CheckBox)this.gdvSpecialPlanResolve.Rows[i].Cells[0].FindControl("ckbSelect"));
                _chk.Checked = true;
            }
        }
        else
        {
            for (int i = 0; i < this.gdvSpecialPlanResolve.Rows.Count; i++)
            {
                CheckBox _chk = ((CheckBox)this.gdvSpecialPlanResolve.Rows[i].Cells[0].FindControl("ckbSelect"));
                _chk.Checked = false;
            }

        }

    }

    /// <summary>
    /// 保存事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //用于记录专项分解计划id的序号
        int _SpecialPlanDetailId = 0;
        List<object[]> _valueList = new List<object[]>();
        object[] _valueSpecialPlanId = new object[1];
        _valueSpecialPlanId[0] = Utility.HttpHelp.getParamsInt("SpecialPlanId");
        DataTable _SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(_valueSpecialPlanId);
        if (_SpecialPlan.Rows.Count > 0)
        {
            //将选择好的月计划记录加入集合
            for (int i = 1; i < this.gdvSpecialPlanResolve.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvSpecialPlanResolve.Rows[i].Cells[0].FindControl("ckbSelect");
                if (ckb.Checked == true)
                {
                    Response.Write(this.gdvSpecialPlanResolve.DataKeys[i]["Id"].ToString());
                    if (this.gdvSpecialPlanResolve.DataKeys[i]["Id"].ToString().Length == 0)
                    {
                        //循环一次自增1次
                        _SpecialPlanDetailId++;
                        object[] _value = new object[22];
                        _value[0] = this.gdvSpecialPlanResolve.Rows[i].Cells[1].Text;
                        _value[1] = Utility.HttpHelp.getParamsInt("SpecialPlanId");
                        _value[2] = Convert.ToDateTime(this.gdvSpecialPlanResolve.Rows[i].Cells[2].Text);
                        _value[3] = Convert.ToDateTime(this.gdvSpecialPlanResolve.Rows[i].Cells[3].Text);
                        _value[4] = this.gdvSpecialPlanResolve.Rows[i].Cells[4].Text;
                        //前置任务
                        _value[5] = this.gdvSpecialPlanResolve.Rows[i].Cells[5].Text;
                        //工作描述空
                        _value[6] = string.Empty;
                        //masterdepartment
                        _value[7] = this.gdvSpecialPlanResolve.Rows[i].Cells[7].Text;
                        _value[8] = this.gdvSpecialPlanResolve.Rows[i].Cells[6].Text;
                        //slavadepartment
                        _value[9] = this.gdvSpecialPlanResolve.Rows[i].Cells[8].Text;
                        _value[10] = this.gdvSpecialPlanResolve.Rows[i].Cells[9].Text;
                        //评估人
                        _value[11] = this.gdvSpecialPlanResolve.Rows[i].Cells[10].Text;
                        //评估意见
                        _value[12] = string.Empty;
                        //状态
                        _value[13] = 0;
                        //优先级
                        _value[14] = this.gdvSpecialPlanResolve.Rows[i].Cells[11].Text;
                        //重要程度
                        _value[15] = string.Empty;
                        //完成状态
                        _value[16] = string.Empty;
                        //完成状态描述
                        _value[17] = string.Empty;
                        //审核人
                        _value[18] = string.Empty;
                        //审核流程
                        _value[19] = Convert.ToInt32(_SpecialPlan.Rows[0]["VerifyCircuitId"].ToString());
                        //发起人
                        _value[20] = _SpecialPlan.Rows[0]["Sponsor"].ToString();
                        //备注
                        _value[21] = this.gdvSpecialPlanResolve.Rows[i].Cells[12].Text;
                        _valueList.Add(_value);
                    }
                }
            }
            if (_valueList.Count > 0)
            {
                int result = new BLL.SpecialPlan().addWithTransactionForResolve(_valueList);
                if (result == 0)
                {
                    Utility.HttpHelp.alert("至少选择一条你要保存的专项分解计划！", Page);
                }
                else
                {
                    bindSpecialPlan();
                    Utility.HttpHelp.closeWindowNoFresh("AddSpecialPlan.aspx", Page);
                }
            }
        }
    }


    /// <summary>
    /// 创建空DataTable用于绑定GridView
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-16</date>
    DataTable createDataTable()
    {
        DataTable _dataTable = new DataTable();
        _dataTable.Columns.Add("Id");
        _dataTable.Columns.Add("SpecialPlanDetailSortId");
        _dataTable.Columns.Add("SpecialPlanId");
        _dataTable.Columns.Add("WorkItem");
        _dataTable.Columns.Add("WorkItemDesc");
        _dataTable.Columns.Add("StartTime");
        _dataTable.Columns.Add("CompleteTime");
        _dataTable.Columns.Add("PreposeTask");
        _dataTable.Columns.Add("MasterPeople");
        _dataTable.Columns.Add("MasterDepartment");
        _dataTable.Columns.Add("SlaveDepartment");
        _dataTable.Columns.Add("SlaveDepartmentDuty");
        _dataTable.Columns.Add("EvaluatePeople");
        _dataTable.Columns.Add("State");
        _dataTable.Columns.Add("CheckNote");
        _dataTable.Columns.Add("PriorityLevel");
        _dataTable.Columns.Add("CompleteState");
        _dataTable.Columns.Add("CompleteDesc");
        _dataTable.Columns.Add("VerifyPeople");
        _dataTable.Columns.Add("VerifyCircuitId");
        _dataTable.Columns.Add("Sponsor");
        _dataTable.Columns.Add("Remart");
        return _dataTable;
    }

    /// <summary>
    /// 添加事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        int _isnull = isNull();
        if (_isnull == 0)
        {
            Utility.HttpHelp.alert("请输入完整", Page);
            return;
        }
        else
        {
            if (this.txtSpecialPlanDetailSortId.Value.Length == 0)
            {
                Utility.HttpHelp.alert("计划编号不能为空！", Page);
                return;
            }
            if (!verifyDate())
            {
                return;
            }
            if (this.txtSlaveDepartment.Value != "独立完成")
            {
                if (this.txtSlaveDepartmentDuty.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("配合部门责任字数不得低于32个字符", Page);
                    return;
                }
            }

            if (this.txtMasterPeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("责任人不可为多人！", Page);
                return;
            }
            if (this.txtEvaluatePeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("评估人不可为多人！", Page);
                return;
            }
            DataTable SpecialPlanResolve = createDataTable();
            //获取GridView当前内容导入DataTable
            for (int i = 0; i < this.gdvSpecialPlanResolve.Rows.Count; i++)
            {
                DataRow _drGridView = SpecialPlanResolve.NewRow();
                _drGridView["SpecialPlanDetailSortId"] = this.gdvSpecialPlanResolve.Rows[i].Cells[1].Text.ToString();
                _drGridView["SpecialPlanId"] = this.gdvSpecialPlanResolve.DataKeys[i]["SpecialPlanId"].ToString();
                _drGridView["StartTime"] = this.gdvSpecialPlanResolve.Rows[i].Cells[2].Text.ToString();
                _drGridView["CompleteTime"] = this.gdvSpecialPlanResolve.Rows[i].Cells[3].Text.ToString();
                _drGridView["WorkItem"] = this.gdvSpecialPlanResolve.Rows[i].Cells[4].Text.ToString();

                _drGridView["PreposeTask"] = this.gdvSpecialPlanResolve.Rows[i].Cells[5].Text.ToString();
                _drGridView["MasterDepartment"] = this.gdvSpecialPlanResolve.Rows[i].Cells[6].Text.ToString();
                _drGridView["MasterPeople"] = this.gdvSpecialPlanResolve.Rows[i].Cells[7].Text.ToString();
                _drGridView["SlaveDepartment"] = this.gdvSpecialPlanResolve.Rows[i].Cells[8].Text.ToString();
                _drGridView["SlaveDepartmentDuty"] = this.gdvSpecialPlanResolve.Rows[i].Cells[9].Text.ToString();
                _drGridView["EvaluatePeople"] = this.gdvSpecialPlanResolve.Rows[i].Cells[10].Text.ToString();
                _drGridView["PriorityLevel"] = this.gdvSpecialPlanResolve.Rows[i].Cells[11].Text.ToString();
                _drGridView["Remart"] = this.gdvSpecialPlanResolve.Rows[i].Cells[12].Text.ToString();
                _drGridView["Id"] = this.gdvSpecialPlanResolve.DataKeys[i]["Id"].ToString();
                _drGridView["Sponsor"] = this.gdvSpecialPlanResolve.DataKeys[i]["Sponsor"].ToString();
                SpecialPlanResolve.Rows.Add(_drGridView);
            }
            //获取当前添加的内容
            DataRow _drTable = SpecialPlanResolve.NewRow();
            _drTable["SpecialPlanDetailSortId"] = this.txtSpecialPlanDetailSortId.Value;
            _drTable["SpecialPlanId"] = string.Empty;
            _drTable["StartTime"] = this.txtStartTime.Text;
            _drTable["CompleteTime"] = this.txtCompleteTime.Text;
            _drTable["WorkItem"] = this.txtWorkItem.Text;

            _drTable["PreposeTask"] = this.txtPreposeTask.Text;
            _drTable["MasterDepartment"] = this.txtMasterDepartment.Text;
            _drTable["MasterPeople"] = this.txtMasterPeople.Value;
            _drTable["SlaveDepartment"] = this.txtSlaveDepartment.Value;
            _drTable["SlaveDepartmentDuty"] = this.txtSlaveDepartmentDuty.Text;
            _drTable["EvaluatePeople"] = this.txtEvaluatePeople.Value;
            _drTable["PriorityLevel"] = this.drpPriorityLevel.SelectedItem.Text;
            _drTable["Remart"] = this.txtRemark.Text;


            SpecialPlanResolve.Rows.Add(_drTable);
            this.gdvSpecialPlanResolve.DataSource = SpecialPlanResolve;
            this.gdvSpecialPlanResolve.DataBind();
            //隐藏首行，只保留表头
            this.gdvSpecialPlanResolve.Rows[0].Visible = false;
        }

        #region 善后处理事件
        this.txtCompleteTime.Text = "";
        this.txtSpecialPlanDetailSortId.Value = "";
        this.txtStartTime.Text = "";

        #endregion
        if (Utility.HttpHelp.getParamsInt("SpecialPlanId") > 0)
        {
            this.txtSpecialPlanDetailSortId.Value = "专" + Utility.HttpHelp.getParamsInt("SpecialPlanSortId") + "." + this.gdvSpecialPlanResolve.Rows.Count.ToString();
        }
        else
        {
            this.txtSpecialPlanDetailSortId.Value = "专" + "1." + this.gdvSpecialPlanResolve.Rows.Count.ToString();
        }
    }



    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDel_Click(object sender, EventArgs e)
    {
        DataTable SpeicalPlan = createDataTable();
        //获取GridView当前内容导入DataTable
        for (int i = 0; i < this.gdvSpecialPlanResolve.Rows.Count; i++)
        {
            DataRow _drGridView = SpeicalPlan.NewRow();
            _drGridView["SpecialPlanDetailSortId"] = this.gdvSpecialPlanResolve.Rows[i].Cells[1].Text.ToString();
            _drGridView["SpecialPlanId"] = this.gdvSpecialPlanResolve.DataKeys[i]["SpecialPlanId"].ToString();
            _drGridView["StartTime"] = this.gdvSpecialPlanResolve.Rows[i].Cells[2].Text.ToString();
            _drGridView["CompleteTime"] = this.gdvSpecialPlanResolve.Rows[i].Cells[3].Text.ToString();
            _drGridView["WorkItem"] = this.gdvSpecialPlanResolve.Rows[i].Cells[4].Text.ToString();
            _drGridView["PreposeTask"] = this.gdvSpecialPlanResolve.Rows[i].Cells[5].Text.ToString();
            _drGridView["MasterDepartment"] = this.gdvSpecialPlanResolve.Rows[i].Cells[6].Text.ToString();
            _drGridView["MasterPeople"] = this.gdvSpecialPlanResolve.Rows[i].Cells[7].Text.ToString();
            _drGridView["SlaveDepartment"] = this.gdvSpecialPlanResolve.Rows[i].Cells[8].Text.ToString();
            _drGridView["SlaveDepartmentDuty"] = this.gdvSpecialPlanResolve.Rows[i].Cells[9].Text.ToString();
            _drGridView["EvaluatePeople"] = this.gdvSpecialPlanResolve.Rows[i].Cells[10].Text.ToString();
            _drGridView["PriorityLevel"] = this.gdvSpecialPlanResolve.Rows[i].Cells[11].Text.ToString();
            _drGridView["Remart"] = this.gdvSpecialPlanResolve.Rows[i].Cells[12].Text.ToString();
            _drGridView["Id"] = this.gdvSpecialPlanResolve.DataKeys[i]["Id"].ToString();
            _drGridView["Sponsor"] = this.gdvSpecialPlanResolve.DataKeys[i]["Sponsor"].ToString();
            SpeicalPlan.Rows.Add(_drGridView);
        }
        int _rowId = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        _rowId = iRow.RowIndex;//得到该行的索引
        if (SpeicalPlan.Rows.Count > _rowId)
        {
            if (this.gdvSpecialPlanResolve.DataKeys[_rowId]["Id"].ToString().Length == 0 || this.gdvSpecialPlanResolve.DataKeys[_rowId]["Id"].ToString() == "&nbsp;")
            {
                SpeicalPlan.Rows.RemoveAt(_rowId);
                this.gdvSpecialPlanResolve.DataSource = SpeicalPlan;
                this.gdvSpecialPlanResolve.DataBind();
                this.gdvSpecialPlanResolve.Rows[0].Visible = false;
                if (Utility.HttpHelp.getParamsInt("SpecialPlanId") > 0)
                {
                    this.txtSpecialPlanDetailSortId.Value = "专" + Utility.HttpHelp.getParamsInt("SpecialPlanSortId") + "." + this.gdvSpecialPlanResolve.Rows.Count.ToString();
                }
                else
                {
                    this.txtSpecialPlanDetailSortId.Value = "专" + "1." + this.gdvSpecialPlanResolve.Rows.Count.ToString();
                }

            }
            else
            {
                object[] _SpecialPlanId = new object[1];
                _SpecialPlanId[0] = Convert.ToInt32(this.gdvSpecialPlanResolve.DataKeys[_rowId]["SpecialPlanId"].ToString());
                DataTable SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(_SpecialPlanId);
                if (SpecialPlan.Rows.Count > 0)
                {
                    if (Convert.ToInt32(SpecialPlan.Rows[0]["State"].ToString()) == 0)
                    {
                        SpecialPlan.Rows.RemoveAt(_rowId);
                        object[] _value = new object[1];
                        _value[0] = Convert.ToInt32(this.gdvSpecialPlanResolve.DataKeys[_rowId]["Id"].ToString());
                        int result = new BLL.SpecialPlan().DelDetailById(_value);
                        if (result == 0)
                        {
                            Utility.Error.RedirectErrorPage("删除专项分解未成功，请重试");
                        }
                        else
                        {
                            this.gdvSpecialPlanResolve.DataSource = SpeicalPlan;
                            this.gdvSpecialPlanResolve.DataBind();
                            this.gdvSpecialPlanResolve.Rows[0].Visible = false;
                            if (Utility.HttpHelp.getParamsInt("SpecialPlanId") > 0)
                            {
                                this.txtSpecialPlanDetailSortId.Value = "专" + Utility.HttpHelp.getParamsInt("SpecialPlanSortId") + "." + this.gdvSpecialPlanResolve.Rows.Count.ToString();
                            }
                            else
                            {
                                this.txtSpecialPlanDetailSortId.Value = "专" + "1." + this.gdvSpecialPlanResolve.Rows.Count.ToString();
                            }
                        }
                    }
                    else
                    {
                        Utility.HttpHelp.alert("该专项分解所属的专项计划已提交，不可以删除！", Page);

                    }
                }
            }
        }

    }

    /// <summary>
    /// 修改事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModify_Click(object sender, EventArgs e)
    {
        Model.UserInfo objUserInfo = new Model.UserInfo();
        int SpecialPlanDetailId = 0;
        int SpecialPlanId = 0;
        string SpecialPlanDetailSortId = string.Empty;
        int _count = 0;
        string _sponsor = "";
        for (int i = 0; i < this.gdvSpecialPlanResolve.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvSpecialPlanResolve.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (this.gdvSpecialPlanResolve.DataKeys[i]["Id"].ToString() == "")
                {
                }
                else
                {
                    _count++;
                    SpecialPlanDetailSortId = this.gdvSpecialPlanResolve.Rows[i].Cells[1].Text;
                    SpecialPlanDetailId = Convert.ToInt32(this.gdvSpecialPlanResolve.DataKeys[i]["Id"].ToString());
                    SpecialPlanId = Convert.ToInt32(this.gdvSpecialPlanResolve.DataKeys[i]["SpecialPlanId"].ToString());
                    _sponsor = this.gdvSpecialPlanResolve.DataKeys[i]["Sponsor"].ToString();
                }
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个要修改的专项分解计划", Page);
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能选择一个要修改的专项分解计划", Page);
        }
        if (_count == 1)
        {
            if (objUserInfo.UserName == _sponsor || objUserInfo.UserName == "admin")
            {
                object[] _value = new object[1];
                _value[0] = SpecialPlanId;
                DataTable _SpecialPlan = new BLL.SpecialPlan().GetSpecialPlanById(_value);
                if (_SpecialPlan.Rows.Count > 0)
                {
                    if (Convert.ToInt32(_SpecialPlan.Rows[0]["State"].ToString()) == 0
                        || objUserInfo.UserName == "admin"
                        || Convert.ToInt32(_SpecialPlan.Rows[0]["State"].ToString()) == -1)
                    {
                        string _url = "ModifySpecialPlanDetail.aspx?SpecialPlanDetailId=" + SpecialPlanDetailId + "&SpecialPlanDetailSortId=" + SpecialPlanDetailSortId + "&SpecialPlanId=" + Utility.HttpHelp.getParamsString("SpecialPlanId");
                        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','ModifyQuarterPlanResolveDetail','height=200,width=1000,top=400,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                    }
                    else
                    {
                        Utility.HttpHelp.alert("该专项分解所属的专项计划已提交，不可以修改！", Page);
                    }
                }
            }
            else
            {
                Utility.HttpHelp.alert("发起人或计划管理员才可以执行修改操作", Page);
            }

        }
    }

    /// <summary>
    /// 提交专项分解计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int _count = 0;

        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvSpecialPlanResolve.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvSpecialPlanResolve.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (Convert.ToInt32(this.gdvSpecialPlanResolve.DataKeys[i]["Id"].ToString()) > 0)
                {
                    object[] _value = new object[2];
                    _value[0] = Convert.ToInt32(this.gdvSpecialPlanResolve.DataKeys[i]["Id"].ToString());
                    _value[1] = objUserInfo.UserName;
                    _valueList.Add(_value);
                    _count++;
                }
            }
        }
        if (_valueList.Count > 0)
        {
            int result = new BLL.SpecialPlan().SubmitDetailWithTransaction(_valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("提交专项计划明细未成功，请重试！");
            }
        }
        else
        {
            Utility.HttpHelp.alert("请至少选择一个", Page);
        }
        
    }
}